package com.example.summary.sort;

import com.alibaba.fastjson.JSON;

/**
 * Created by wzn on 2019/1/5.
 */

/**
 * 选择最小的一个交换位置
 */
public class Choose {
    public static void main(String[] args) {
        int[] x = {9, 7, 3, 10, 11, 23, 4, 1};

        sort2(x);
        System.out.println(JSON.toJSONString(x));
    }

    private static void sort(int[] x) {
        for (int i = 0; i < x.length - 1; i++) {
            int index = i;
            for (int j = i + 1; j < x.length; j++) {
                if (x[j] > x[index]) {
                    index = j;
                }
            }
            int tmp = x[i];
            x[i] = x[index];
            x[index] = tmp;
        }
    }

    private static void sort2(int[] x) {
        for (int i = 0; i < x.length - 1; i++) {
            int index = i;

            for (int j = i + 1; j < x.length; j++) {
                if (x[j]< x[index]){
                    index = j;
                }
            }

            int temp = x[i];
            x[i] = x[index];
            x[index] = temp;
        }
    }
}
